package com.multithreading.chart1.waitAndnotify;


/**
 * @description: 当一个线程调用共享对象的wait方法被挂起后，如果其他线程中断了该线程，
 * 则该线程会抛出interruptException异常并返回。
 * @author chenqb
 * @date 2021/7/14 9:57
 * @version 1.0
 */
public class WaitNotifyInterrupt {
    static Object obj= new Object();

    public static void main(String[] args) throws InterruptedException {
        //创建线程
        Thread threadA= new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("----begin----");
                    //阻塞当前线程
                    synchronized (obj){
                        obj.wait();
                    }
                    System.out.println("---end---");
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        threadA.start();
        Thread.sleep(1000);
        System.out.println("---begin interrupt threadA---");
        threadA.interrupt();
        System.out.println("---end interrupt threadA---");
    }

}
